﻿import NProgress from 'nprogress'
import axios from 'axios';
export default {
    data() {
        return {
            logining: false,
            ruleForm2: {
                account: 'admin',
                checkPass: '123456'
            },
            rules2: {
                account: [
                    { required: true, message: '请输入账号', trigger: 'blur' },
                    //{ validator: validaePass }
                ],
                checkPass: [
                    { required: true, message: '请输入密码', trigger: 'blur' },
                    //{ validator: validaePass2 }
                ]
            },
            checked: true,
            restaurants: [],
            state1: '',
            state2: '',
            loginStr: "",
            pwd: ""
        };
    },
    mounted() {
        //  this.restaurants = this.loadAll();
        this.pageSetting();
    },
    methods: {
        pageSetting() {
            if (localStorage.loginStr) {
                this.loginStr = localStorage.loginStr
            }

            if (localStorage.pwd) {
                this.pwd = localStorage.pwd
            }
        },

        querySearch(queryString, cb) {
            var restaurants = this.restaurants;
            var results = queryString ? restaurants.filter(this.createFilter(queryString)) : restaurants;
            // 调用 callback 返回建议列表的数据
            cb(results);
        },
        createFilter(queryString) {
            return (restaurant) => {
                return (restaurant.value.indexOf(queryString.toLowerCase()) === 0);
            };
        },

        handleSelect(item) {
            console.log(item);
        },
        test2() {

            axios.post('/a', {
                class: 'customer',
                para: 'getCustomerList',
                j: {

                }

            }).then(function (response) {
                console.log(response);
            }).catch(function (error) {
                console.log(error);
            });

        },

        handleReset2() {
            this.$refs.ruleForm2.resetFields();
        },
        LoginIn(ev) {


            if (this.checked) {
                //点选了记住密码

                localStorage.loginStr = this.loginStr
                localStorage.pwd = this.pwd
            }
            else {
                delete localStorage.pwd;

            }


            axios.post("/a", {
                class: "member",
                para: "LoginIn",
                j: {
                    loginStr: this.loginStr,
                    pwd: this.pwd
                }
            }).then((res) => {
                if (res.data.re == "ok") {

                    sessionStorage.setItem('member', JSON.stringify({ username: "admin", name: " 王力", avatar: "/static/images/logo.png", companyCode: "1999" }));
                    localStorage.memberId = 'wangli';

                    this.$router.push({ path: '/customerList' });

                } else {
                    alert(JSON.stringify(res.data));
                }
            });






        }
    }
}